//
//  ExWKWebViewController.swift
//  Swift-Example
//
//  Created by a on 12/11/2019.
//  Copyright © 2019 apang.men. All rights reserved.
//

import UIKit
import WebKit

class ExWKWebViewController: UIViewController,WKUIDelegate,WKNavigationDelegate  {
    
    lazy var webView:WKWebView = {
        let config = WKWebViewConfiguration()
        let __webView = WKWebView.init(frame: CGRect.zero, configuration: config)
        return __webView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white
        // Do any additional setup after loading the view.
        webView.uiDelegate = self
        webView.navigationDelegate = self
        webView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(webView)
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-(0)-[webView]-(0)-|", options: NSLayoutConstraint.FormatOptions.init(), metrics:nil, views: ["webView":webView]))
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-(0)-[webView]-(0)-|", options: NSLayoutConstraint.FormatOptions.init(), metrics:nil, views: ["webView":webView]))
        NSLog("viewDidLoad", "")
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        (UIApplication.shared.delegate as! AppDelegate).interfacceOrientaion = [.portrait, .landscape]
        let url = NSURL.init(string: "https://www.baidu.com")
        let request = NSURLRequest.init(url: url! as URL)
        NSLog("viewWillAppear", "")
        DispatchQueue.main.asyncAfter(deadline: .now()+2) {
            NSLog("asyncAfter", "")
            self.webView.load(request as URLRequest)
        }
    }
}
